﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Groupbox;
using System.Collections.Generic;
using System.Xml.Linq;

namespace OntoWPFSilverlight.Widget
{
    [OntoWPFSilverlight.Annotation.Widget("RadioButtonGroupBox")]
    public class RadioButtonGroupBox : WidgetCanvas, Interfaces.IWidgetWithItems
    {
        GroupBox groupBox = null;
        WrapPanel wrapPanel = null;
        
        public RadioButtonGroupBox() : base()
        {
            Build();
        }

        private void Build()
        {
            groupBox = new GroupBox();
            wrapPanel = new WrapPanel();
            
            wrapPanel.Orientation = Orientation.Horizontal;
            wrapPanel.HorizontalAlignment = HorizontalAlignment.Stretch;
            wrapPanel.VerticalAlignment = VerticalAlignment.Stretch;
            
            groupBox.Content = wrapPanel;
            groupBox.Header = "Label";
            
            DockPanel.SetDock(groupBox, Dock.Top);
            
            this.Children.Add(groupBox);
        }

        //public void AddLabel(string text) 
        //{
        //    groupBox.Header = text;
        //}

        public override string Text
        {
            get
            {
                return groupBox.Header.ToString();
            }
            set
            {
                groupBox.Header = value;
            }
        }


        #region IWidgetWithItems Membri di

        OntoWPFSilverlight.Node ontologyNode;

        public OntoWPFSilverlight.Node Node
        {
            get
            {
                return ontologyNode;
            }
            set
            {
                ontologyNode = value;
            }
        }

        OntoWPFSilverlight.Xml.OntologiesNodes ontologiesNodes = null;
        public OntoWPFSilverlight.Xml.OntologiesNodes OntologiesNodes
        {
            get
            {
                return ontologiesNodes;
            }
            set
            {
                this.ontologiesNodes = value;
            }
        }


        public void update(List<Node> nodes)
        {
            foreach (Node _node in nodes)
            {
                RadioButton tempRadio = new RadioButton();
                tempRadio.Name = _node.Name;
                tempRadio.Content = _node.Alias;
                try
                {
                    tempRadio.FontSize = Double.Parse(this.WidgetFont.Size);
                }
                catch (Exception) {}
                try
                {
                    tempRadio.FontFamily = new FontFamily(this.WidgetFont.Name);
                }
                catch { }
                tempRadio.IsChecked = false;
                wrapPanel.Children.Add(tempRadio);
            }
        }

        public void update()
        {
            update(this.ontologiesNodes.Nodes);
        }

        #endregion
    }
}
